<template>
  <section class="newsletter-section py-16 bg-white">
    <div
      class="container flex flex-col md:flex-row items-center justify-between"
    >
      <div class="mb-8 md:mb-0">
        <h2 class="text-2xl md:text-3xl font-bold text-dark"
          >订阅我们的最新资讯</h2
        >
        <p class="mt-4 text-neutral max-w-lg"
          >获取最新乐谱上架、促销活动和独家音乐内容推荐</p
        >
      </div>
      <el-form :inline="true" class="newsletter-form" @submit.prevent>
        <el-form-item>
          <el-input v-model="email" placeholder="请输入您的邮箱" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="subscribe">订阅</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-dialog
      v-model="dialogVisible"
      title="订阅成功"
      width="320px"
      :show-close="false"
    >
      <span>感谢您的订阅！我们会定期为您推送最新乐谱和活动信息。</span>
      <template #footer>
        <el-button type="primary" @click="dialogVisible = false"
          >关闭</el-button
        >
      </template>
    </el-dialog>
  </section>
</template>

<script setup>
  import { ref } from 'vue';

  const email = ref('');
  const dialogVisible = ref(false);
  function subscribe() {
    if (email.value && /.+@.+\..+/.test(email.value)) {
      dialogVisible.value = true;
      email.value = '';
    } else {
      // 可用 Element Plus 的消息组件优化
      alert('请输入有效的邮箱地址');
    }
  }
</script>

<style scoped>
  .newsletter-section {
    background: #fff;
  }
  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
  }
  .newsletter-form {
    display: flex;
    align-items: center;
  }
</style>
